package com.taoyibao.hongcanting.ui.mine.delegate;

import android.view.View;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.constant.NetCode;
import com.taoyibao.hongcanting.model.CompanyBaseModel;
import com.taoyibao.hongcanting.model.UserInfoModel;
import com.taoyibao.hongcanting.ui.mine.activity.SetPayPwdStepOneActivity;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.FileUtils;

import java.util.List;

/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 11:56
 */
public class SettingDelegate extends BackToolbarDelegate implements View.OnClickListener {

    private String mTitle = "支付设置";
    private TextView mCacheSize;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("设置");
        get(R.id.layout_setting_setPwd).setOnClickListener(this);
        get(R.id.layout_setting_clearCache).setOnClickListener(this);
        mCacheSize = get(R.id.tv_setting_size);
        setCacheSize();
    }

    /**
     * 设置缓存大小
     */
    public void setCacheSize() {
        String totalCacheSize = FileUtils.getTotalCacheSize();
        mCacheSize.setText(totalCacheSize);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_setting_setPwd://设置支付密码
                SetPayPwdStepOneActivity.open(getActivity(), mTitle);
                break;
            case R.id.layout_setting_clearCache://清除缓存
                FileUtils.clearAllCache();
                setCacheSize();
                break;
        }
    }

    public void setData(CompanyBaseModel<List<UserInfoModel>> data) {
        if (data.code == NetCode.HTTP_200 && data.data != null && data.data.size() > 0) {
            UserInfoModel userInfoModel = data.data.get(0);
            if (userInfoModel.pay_pwd == 1) {//有支付密码
                mTitle = CodeUtils.getIdString(R.string.string_modifyPayPwd);
            } else if (userInfoModel.pay_pwd == 0) {
                mTitle = CodeUtils.getIdString(R.string.string_setPayPwd);
            }
        }
    }
}
